import { SEND_MESSAGE } from "../contants/ActionTypes";

const initialState = {
    messages:[
            {
            fromWho:false,//true is from myself
            text:"abc",
            id:0
            }
        ]
};

export default function anonymousChat(state = initialState , action){
    switch(action.type){
        case SEND_MESSAGE:
            return{
                ...state,
                messages:[...state.messages,
                    {
                        fromWho:true,
                        text:action.text,
                        id:state.messages.reduce((maxId,message)=> Math.max(message.id,maxId),-1)+1
                    }
                ]
            }
        default:
            return state;            
    }   

}

